package com.fwh.web.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 首页跳转
 *
 * @return
 * @author:fwh [2019/4/3 && 17:08]
 */
@RestController
public class DefaultViewController {
    /**
     * 首页拦截--跳转到登录页面
     *
     * @param request
     * @param response
     * @return java.lang.String
     * @author:fwh [2019/4/12 && 13:53]
     */
    @GetMapping("/")
    private String login(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("跳转到登录页面...");
        try {
            request.getRequestDispatcher("/login.html").forward(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "forward:/login.html";
    }

    /**
     * 跳转到首页
     *
     * @param request
     * @param response
     * @return java.lang.String
     * @author:fwh [2019/4/12 && 13:53]
     */
    @GetMapping("/index")
    private String index(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("跳转到登录页面...");
        try {
            request.getRequestDispatcher("/index.html").forward(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "forward:/index.html";
    }

}
